/*
  Copyright (C) 2011 Zhao Ming(zhao.ming29@gmail.com)

  All rights reserved.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License version 2.1, as
  published by the Free Software Foundation.  This program is
  distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LRCRECV_H
#define __LRCRECV_H
#include "Wash.h"
#include "macAddr.h"
#include "GHGS.h"
#include "RecvBuf.h"

#define MAXSEG 2
#define MAXMES 1024

struct Message {
	int mes[MAXSEG];
	int time;
	int len;
};

class CLRCReceiver {
	private:
		static int W[];
		static int D[];
		CWash *aWash;
		GHGS *ghgsI[2];
		GHGS *ghgsQ[2];
		CRecvBuf *rBuf;
		
		char *buf;
		int *iMask;
		int *washBuf;
		int len;
		int thresholdPilot;
		int maxSeg;
		int nowTime;
		int skip;
		
struct complex {
	int i;
	int q;
};		
		struct complex pilot[MAXSEG+1];
		struct complex mid[4];
		struct complex nowPilot;
		void carrier( int p );
		int power( struct complex a ) { return (a.i*a.i)/256+(a.q*a.q)/256; }  
		
	public:
		CLRCReceiver( int addrA, int addrB, int maxSeg, int tP );
		~CLRCReceiver();
		int recv( char *t, int k, struct Message res[] );
		
};	
#endif
